{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Latent Factor Collaborative Filtering using Deep Learning"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 166,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#!/usr/bin/python\n",
    "# -*- coding: utf-8 -*-\n",
    "#Load the packages \n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from pathlib import Path\n",
    "from sklearn.model_selection import train_test_split\n",
    "from keras.layers import Embedding, Reshape,dot,Input,Dense\n",
    "from keras.models import Sequential,Model\n",
    "from keras.callbacks import Callback, EarlyStopping, ModelCheckpoint\n",
    "from keras.utils.vis_utils import plot_model\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Define the Required Functions**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 172,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_dir = Path('/home/santanu/ML_DS_Catalog-/Collaborating Filtering/ml-100k/')\n",
    "outdir = Path('/home/santanu/ML_DS_Catalog-/Collaborating Filtering/ml-100k/')\n",
    "\n",
    "#Function to read data \n",
    "def create_data(rating,header_cols):\n",
    "    data = pd.read_csv(rating,header=None,sep='\\t')\n",
    "    #print(data)\n",
    "    data.columns = header_cols\n",
    "    return data\n",
    " \n",
    "#Movie id to movie name dict \n",
    "def create_movie_dict(movie_file):\n",
    "    print(movie_file)\n",
    "    df = pd.read_csv(movie_file,sep='|', encoding='latin-1',header=None)\n",
    "    movie_dict = {}\n",
    "    movie_ids = list(df[0].values)\n",
    "    movie_name = list(df[1].values)\n",
    "    for k,v in zip(movie_ids,movie_name):\n",
    "        movie_dict[k] = v \n",
    "    return movie_dict\n",
    "# Function to create training validation and test data\n",
    "def train_val(df,val_frac=None):\n",
    "    X,y = df[['userID','movieID']].values,df['rating'].values\n",
    "    #Offset the ids by 1 for the ids to start from zero\n",
    "    X = X - 1 \n",
    "    if val_frac != None:\n",
    "        X_train, X_test, y_train, y_val = train_test_split(X, y, test_size=val_frac,random_state=0)\n",
    "        return X_train, X_val, y_train, y_val\n",
    "    else:\n",
    "        return X,y\n",
    "\n",
    "#  Define Model\n",
    "# Converts the userId and the MovieId to embedding sizes of a given latent dimension and then takes the dot product \n",
    "# of those embeddings to get the rating score. \n",
    "def model(max_users,max_movies,latent_factors):\n",
    "    user_ID = Input(shape=(1,))\n",
    "    movie_ID = Input(shape=(1,))\n",
    "    x = Embedding(max_users,latent_factors, input_length=1)(user_ID)\n",
    "    print(x.shape)\n",
    "    y = Embedding(max_movies,latent_factors, input_length=1)(movie_ID)\n",
    "    print(y.shape)\n",
    "    out = dot([x,y],axes=2, normalize=False)\n",
    "    out= Reshape((1,))(out)\n",
    "    model = Model(inputs=[user_ID,movie_ID],outputs=out)\n",
    "    print(model.summary())\n",
    "    return model\n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Data Processing and Model Training**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/santanu/ML_DS_Catalog-/Collaborating Filtering/ml-100k/u.item\n",
      "Number of users 943\n",
      "Number of movies 1650\n",
      "(?, 1, 40)\n",
      "(?, 1, 40)\n",
      "__________________________________________________________________________________________________\n",
      "Layer (type)                    Output Shape         Param #     Connected to                     \n",
      "==================================================================================================\n",
      "input_61 (InputLayer)           (None, 1)            0                                            \n",
      "__________________________________________________________________________________________________\n",
      "input_62 (InputLayer)           (None, 1)            0                                            \n",
      "__________________________________________________________________________________________________\n",
      "embedding_61 (Embedding)        (None, 1, 40)        37720       input_61[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "embedding_62 (Embedding)        (None, 1, 40)        66000       input_62[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "dot_31 (Dot)                    (None, 1, 1)         0           embedding_61[0][0]               \n",
      "                                                                 embedding_62[0][0]               \n",
      "__________________________________________________________________________________________________\n",
      "reshape_24 (Reshape)            (None, 1)            0           dot_31[0][0]                     \n",
      "==================================================================================================\n",
      "Total params: 103,720\n",
      "Trainable params: 103,720\n",
      "Non-trainable params: 0\n",
      "__________________________________________________________________________________________________\n",
      "None\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/santanu/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:17: UserWarning: The `nb_epoch` argument in `fit` has been renamed `epochs`.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train on 64000 samples, validate on 16000 samples\n",
      "Epoch 1/30\n",
      " - 4s - loss: 8.8970 - val_loss: 2.0422\n",
      "Epoch 2/30\n",
      " - 3s - loss: 1.3345 - val_loss: 1.0734\n",
      "Epoch 3/30\n",
      " - 3s - loss: 0.9656 - val_loss: 0.9704\n",
      "Epoch 4/30\n",
      " - 3s - loss: 0.8921 - val_loss: 0.9317\n",
      "Epoch 5/30\n",
      " - 3s - loss: 0.8452 - val_loss: 0.9097\n",
      "Epoch 6/30\n",
      " - 3s - loss: 0.8076 - val_loss: 0.8987\n",
      "Epoch 7/30\n",
      " - 3s - loss: 0.7686 - val_loss: 0.8872\n",
      "Epoch 8/30\n",
      " - 3s - loss: 0.7260 - val_loss: 0.8920\n",
      "Epoch 9/30\n",
      " - 3s - loss: 0.6842 - val_loss: 0.8959\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<keras.callbacks.History at 0x7f8b3fbe06a0>"
      ]
     },
     "execution_count": 173,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Data Processing and Model Training \n",
    "\n",
    "train_ratings_df = create_data(f'{data_dir}/u1.base',['userID','movieID','rating','timestamp']) \n",
    "test_ratings_df = create_data(f'{data_dir}/u1.test',['userID','movieID','rating','timestamp']) \n",
    "X_train, X_val,y_train, y_val = train_val(train_ratings_df,val_frac=0.2)\n",
    "movie_dict = create_movie_dict(f'{data_dir}/u.item')\n",
    "num_users = len(train_ratings_df['userID'].unique())\n",
    "num_movies = len(train_ratings_df['movieID'].unique())\n",
    "\n",
    "print(f'Number of users {num_users}')\n",
    "print(f'Number of movies {num_movies}')\n",
    "model = model(num_users,num_movies,40)\n",
    "plot_model(model, to_file='model_plot.png', show_shapes=True, show_layer_names=True)\n",
    "model.compile(loss='mse',optimizer='adam')\n",
    "callbacks = [EarlyStopping('val_loss', patience=2), \n",
    "             ModelCheckpoint(f'{outdir}/nn_factor_model.h5', save_best_only=True)]\n",
    "model.fit([X_train[:,0],X_train[:,1]], y_train, nb_epoch=30, validation_data=([X_val[:,0],X_val[:,1]], y_val), verbose=2, callbacks=callbacks)\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Evaluate on the test dataset**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 176,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hold out test set RMSE: 0.9545832684051578\n"
     ]
    }
   ],
   "source": [
    "#Evaluate on the test dataset \n",
    "from keras.models import load_model\n",
    "model = load_model(f'{outdir}/nn_factor_model.h5')\n",
    "X_test,y_test = train_val(test_ratings_df,val_frac=None)\n",
    "pred = model.predict([X_test[:,0],X_test[:,1]])[:,0]\n",
    "print('Hold out test set RMSE:',(np.mean((pred - y_test)**2)**0.5))\n",
    "pred = np.round(pred)\n",
    "test_ratings_df['predictions'] = pred\n",
    "test_ratings_df['movie_name'] = test_ratings_df['movieID'].apply(lambda x:movie_dict[x])\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Check Evaluation results for the UserID = 1  **"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 177,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>userID</th>\n",
       "      <th>movieID</th>\n",
       "      <th>rating</th>\n",
       "      <th>timestamp</th>\n",
       "      <th>predictions</th>\n",
       "      <th>movie_name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>12</td>\n",
       "      <td>5</td>\n",
       "      <td>878542960</td>\n",
       "      <td>5.0</td>\n",
       "      <td>Usual Suspects, The (1995)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>1</td>\n",
       "      <td>60</td>\n",
       "      <td>5</td>\n",
       "      <td>875072370</td>\n",
       "      <td>5.0</td>\n",
       "      <td>Three Colors: Blue (1993)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>1</td>\n",
       "      <td>64</td>\n",
       "      <td>5</td>\n",
       "      <td>875072404</td>\n",
       "      <td>5.0</td>\n",
       "      <td>Shawshank Redemption, The (1994)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>1</td>\n",
       "      <td>100</td>\n",
       "      <td>5</td>\n",
       "      <td>878543541</td>\n",
       "      <td>5.0</td>\n",
       "      <td>Fargo (1996)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>53</th>\n",
       "      <td>1</td>\n",
       "      <td>114</td>\n",
       "      <td>5</td>\n",
       "      <td>875072173</td>\n",
       "      <td>5.0</td>\n",
       "      <td>Wallace &amp; Gromit: The Best of Aardman Animatio...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>1</td>\n",
       "      <td>170</td>\n",
       "      <td>5</td>\n",
       "      <td>876892856</td>\n",
       "      <td>5.0</td>\n",
       "      <td>Cinema Paradiso (1988)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>1</td>\n",
       "      <td>171</td>\n",
       "      <td>5</td>\n",
       "      <td>889751711</td>\n",
       "      <td>5.0</td>\n",
       "      <td>Delicatessen (1991)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>1</td>\n",
       "      <td>174</td>\n",
       "      <td>5</td>\n",
       "      <td>875073198</td>\n",
       "      <td>5.0</td>\n",
       "      <td>Raiders of the Lost Ark (1981)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>1</td>\n",
       "      <td>183</td>\n",
       "      <td>5</td>\n",
       "      <td>875072262</td>\n",
       "      <td>5.0</td>\n",
       "      <td>Alien (1979)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>90</th>\n",
       "      <td>1</td>\n",
       "      <td>190</td>\n",
       "      <td>5</td>\n",
       "      <td>875072125</td>\n",
       "      <td>5.0</td>\n",
       "      <td>Henry V (1989)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "      <td>887431973</td>\n",
       "      <td>4.0</td>\n",
       "      <td>Shanghai Triad (Yao a yao yao dao waipo qiao) ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>14</td>\n",
       "      <td>5</td>\n",
       "      <td>874965706</td>\n",
       "      <td>4.0</td>\n",
       "      <td>Postino, Il (1994)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>1</td>\n",
       "      <td>81</td>\n",
       "      <td>5</td>\n",
       "      <td>875072865</td>\n",
       "      <td>4.0</td>\n",
       "      <td>Hudsucker Proxy, The (1994)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>1</td>\n",
       "      <td>86</td>\n",
       "      <td>5</td>\n",
       "      <td>878543541</td>\n",
       "      <td>4.0</td>\n",
       "      <td>Remains of the Day, The (1993)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>1</td>\n",
       "      <td>91</td>\n",
       "      <td>5</td>\n",
       "      <td>876892636</td>\n",
       "      <td>4.0</td>\n",
       "      <td>Nightmare Before Christmas, The (1993)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>1</td>\n",
       "      <td>96</td>\n",
       "      <td>5</td>\n",
       "      <td>875072716</td>\n",
       "      <td>4.0</td>\n",
       "      <td>Terminator 2: Judgment Day (1991)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>1</td>\n",
       "      <td>113</td>\n",
       "      <td>5</td>\n",
       "      <td>878542738</td>\n",
       "      <td>4.0</td>\n",
       "      <td>Horseman on the Roof, The (Hussard sur le toit...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>1</td>\n",
       "      <td>129</td>\n",
       "      <td>5</td>\n",
       "      <td>887431908</td>\n",
       "      <td>4.0</td>\n",
       "      <td>Bound (1996)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>68</th>\n",
       "      <td>1</td>\n",
       "      <td>150</td>\n",
       "      <td>5</td>\n",
       "      <td>876892196</td>\n",
       "      <td>4.0</td>\n",
       "      <td>Swingers (1996)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>1</td>\n",
       "      <td>154</td>\n",
       "      <td>5</td>\n",
       "      <td>878543541</td>\n",
       "      <td>4.0</td>\n",
       "      <td>Monty Python's Life of Brian (1979)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>1</td>\n",
       "      <td>175</td>\n",
       "      <td>5</td>\n",
       "      <td>875072547</td>\n",
       "      <td>4.0</td>\n",
       "      <td>Brazil (1985)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>1</td>\n",
       "      <td>177</td>\n",
       "      <td>5</td>\n",
       "      <td>876892701</td>\n",
       "      <td>4.0</td>\n",
       "      <td>Good, The Bad and The Ugly, The (1966)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <td>1</td>\n",
       "      <td>196</td>\n",
       "      <td>5</td>\n",
       "      <td>874965677</td>\n",
       "      <td>4.0</td>\n",
       "      <td>Dead Poets Society (1989)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>1</td>\n",
       "      <td>202</td>\n",
       "      <td>5</td>\n",
       "      <td>875072442</td>\n",
       "      <td>4.0</td>\n",
       "      <td>Groundhog Day (1993)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>1</td>\n",
       "      <td>208</td>\n",
       "      <td>5</td>\n",
       "      <td>878542960</td>\n",
       "      <td>4.0</td>\n",
       "      <td>Young Frankenstein (1974)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>106</th>\n",
       "      <td>1</td>\n",
       "      <td>221</td>\n",
       "      <td>5</td>\n",
       "      <td>887431921</td>\n",
       "      <td>4.0</td>\n",
       "      <td>Breaking the Waves (1996)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>108</th>\n",
       "      <td>1</td>\n",
       "      <td>224</td>\n",
       "      <td>5</td>\n",
       "      <td>875071484</td>\n",
       "      <td>4.0</td>\n",
       "      <td>Ridicule (1996)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>112</th>\n",
       "      <td>1</td>\n",
       "      <td>228</td>\n",
       "      <td>5</td>\n",
       "      <td>878543541</td>\n",
       "      <td>4.0</td>\n",
       "      <td>Star Trek: The Wrath of Khan (1982)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>120</th>\n",
       "      <td>1</td>\n",
       "      <td>242</td>\n",
       "      <td>5</td>\n",
       "      <td>889751633</td>\n",
       "      <td>4.0</td>\n",
       "      <td>Kolya (1996)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>125</th>\n",
       "      <td>1</td>\n",
       "      <td>253</td>\n",
       "      <td>5</td>\n",
       "      <td>874965970</td>\n",
       "      <td>4.0</td>\n",
       "      <td>Pillow Book, The (1995)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58</th>\n",
       "      <td>1</td>\n",
       "      <td>125</td>\n",
       "      <td>3</td>\n",
       "      <td>878542960</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Phenomenon (1996)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61</th>\n",
       "      <td>1</td>\n",
       "      <td>130</td>\n",
       "      <td>3</td>\n",
       "      <td>875072002</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Kansas City (1996)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>1</td>\n",
       "      <td>159</td>\n",
       "      <td>3</td>\n",
       "      <td>875073180</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Basic Instinct (1992)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>115</th>\n",
       "      <td>1</td>\n",
       "      <td>232</td>\n",
       "      <td>3</td>\n",
       "      <td>878543196</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Young Guns (1988)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101</th>\n",
       "      <td>1</td>\n",
       "      <td>213</td>\n",
       "      <td>2</td>\n",
       "      <td>876892896</td>\n",
       "      <td>4.0</td>\n",
       "      <td>Room with a View, A (1986)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>1</td>\n",
       "      <td>27</td>\n",
       "      <td>2</td>\n",
       "      <td>876892946</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Bad Boys (1995)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>1</td>\n",
       "      <td>102</td>\n",
       "      <td>2</td>\n",
       "      <td>889751736</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Aristocats, The (1970)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>1</td>\n",
       "      <td>145</td>\n",
       "      <td>2</td>\n",
       "      <td>875073067</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Lawnmower Man, The (1992)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>1</td>\n",
       "      <td>148</td>\n",
       "      <td>2</td>\n",
       "      <td>875240799</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Ghost and the Darkness, The (1996)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>1</td>\n",
       "      <td>155</td>\n",
       "      <td>2</td>\n",
       "      <td>878542201</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Dirty Dancing (1987)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>109</th>\n",
       "      <td>1</td>\n",
       "      <td>225</td>\n",
       "      <td>2</td>\n",
       "      <td>878542738</td>\n",
       "      <td>3.0</td>\n",
       "      <td>101 Dalmatians (1996)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>116</th>\n",
       "      <td>1</td>\n",
       "      <td>233</td>\n",
       "      <td>2</td>\n",
       "      <td>878542552</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Under Siege (1992)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>124</th>\n",
       "      <td>1</td>\n",
       "      <td>252</td>\n",
       "      <td>2</td>\n",
       "      <td>875240677</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Lost World: Jurassic Park, The (1997)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>127</th>\n",
       "      <td>1</td>\n",
       "      <td>255</td>\n",
       "      <td>2</td>\n",
       "      <td>885345822</td>\n",
       "      <td>3.0</td>\n",
       "      <td>My Best Friend's Wedding (1997)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>132</th>\n",
       "      <td>1</td>\n",
       "      <td>264</td>\n",
       "      <td>2</td>\n",
       "      <td>875071713</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Mimic (1997)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>1</td>\n",
       "      <td>36</td>\n",
       "      <td>2</td>\n",
       "      <td>875073180</td>\n",
       "      <td>2.0</td>\n",
       "      <td>Mad Love (1995)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>1</td>\n",
       "      <td>143</td>\n",
       "      <td>1</td>\n",
       "      <td>875072631</td>\n",
       "      <td>4.0</td>\n",
       "      <td>Sound of Music, The (1965)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>105</th>\n",
       "      <td>1</td>\n",
       "      <td>219</td>\n",
       "      <td>1</td>\n",
       "      <td>878542327</td>\n",
       "      <td>4.0</td>\n",
       "      <td>Nightmare on Elm Street, A (1984)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>1</td>\n",
       "      <td>74</td>\n",
       "      <td>1</td>\n",
       "      <td>889751736</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Faster Pussycat! Kill! Kill! (1965)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>1</td>\n",
       "      <td>112</td>\n",
       "      <td>1</td>\n",
       "      <td>878542441</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Flipper (1996)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>1</td>\n",
       "      <td>140</td>\n",
       "      <td>1</td>\n",
       "      <td>878543133</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Homeward Bound: The Incredible Journey (1993)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>129</th>\n",
       "      <td>1</td>\n",
       "      <td>259</td>\n",
       "      <td>1</td>\n",
       "      <td>875692979</td>\n",
       "      <td>3.0</td>\n",
       "      <td>George of the Jungle (1997)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>130</th>\n",
       "      <td>1</td>\n",
       "      <td>260</td>\n",
       "      <td>1</td>\n",
       "      <td>875071713</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Event Horizon (1997)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>134</th>\n",
       "      <td>1</td>\n",
       "      <td>266</td>\n",
       "      <td>1</td>\n",
       "      <td>885345728</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Kull the Conqueror (1997)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>1</td>\n",
       "      <td>78</td>\n",
       "      <td>1</td>\n",
       "      <td>878543176</td>\n",
       "      <td>2.0</td>\n",
       "      <td>Free Willy (1993)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>1</td>\n",
       "      <td>103</td>\n",
       "      <td>1</td>\n",
       "      <td>878542845</td>\n",
       "      <td>2.0</td>\n",
       "      <td>All Dogs Go to Heaven 2 (1996)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>1</td>\n",
       "      <td>104</td>\n",
       "      <td>1</td>\n",
       "      <td>875241619</td>\n",
       "      <td>2.0</td>\n",
       "      <td>Theodore Rex (1995)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>56</th>\n",
       "      <td>1</td>\n",
       "      <td>120</td>\n",
       "      <td>1</td>\n",
       "      <td>875241637</td>\n",
       "      <td>2.0</td>\n",
       "      <td>Striptease (1996)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>121</th>\n",
       "      <td>1</td>\n",
       "      <td>243</td>\n",
       "      <td>1</td>\n",
       "      <td>875241390</td>\n",
       "      <td>2.0</td>\n",
       "      <td>Jungle2Jungle (1997)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>126</th>\n",
       "      <td>1</td>\n",
       "      <td>254</td>\n",
       "      <td>1</td>\n",
       "      <td>878541392</td>\n",
       "      <td>2.0</td>\n",
       "      <td>Batman &amp; Robin (1997)</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>137 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     userID  movieID  rating  timestamp  predictions  \\\n",
       "2         1       12       5  878542960          5.0   \n",
       "20        1       60       5  875072370          5.0   \n",
       "23        1       64       5  875072404          5.0   \n",
       "45        1      100       5  878543541          5.0   \n",
       "53        1      114       5  875072173          5.0   \n",
       "78        1      170       5  876892856          5.0   \n",
       "79        1      171       5  889751711          5.0   \n",
       "80        1      174       5  875073198          5.0   \n",
       "84        1      183       5  875072262          5.0   \n",
       "90        1      190       5  875072125          5.0   \n",
       "0         1        6       5  887431973          4.0   \n",
       "3         1       14       5  874965706          4.0   \n",
       "34        1       81       5  875072865          4.0   \n",
       "38        1       86       5  878543541          4.0   \n",
       "40        1       91       5  876892636          4.0   \n",
       "42        1       96       5  875072716          4.0   \n",
       "52        1      113       5  878542738          4.0   \n",
       "60        1      129       5  887431908          4.0   \n",
       "68        1      150       5  876892196          4.0   \n",
       "70        1      154       5  878543541          4.0   \n",
       "81        1      175       5  875072547          4.0   \n",
       "82        1      177       5  876892701          4.0   \n",
       "92        1      196       5  874965677          4.0   \n",
       "95        1      202       5  875072442          4.0   \n",
       "97        1      208       5  878542960          4.0   \n",
       "106       1      221       5  887431921          4.0   \n",
       "108       1      224       5  875071484          4.0   \n",
       "112       1      228       5  878543541          4.0   \n",
       "120       1      242       5  889751633          4.0   \n",
       "125       1      253       5  874965970          4.0   \n",
       "..      ...      ...     ...        ...          ...   \n",
       "58        1      125       3  878542960          3.0   \n",
       "61        1      130       3  875072002          3.0   \n",
       "73        1      159       3  875073180          3.0   \n",
       "115       1      232       3  878543196          3.0   \n",
       "101       1      213       2  876892896          4.0   \n",
       "8         1       27       2  876892946          3.0   \n",
       "46        1      102       2  889751736          3.0   \n",
       "66        1      145       2  875073067          3.0   \n",
       "67        1      148       2  875240799          3.0   \n",
       "71        1      155       2  878542201          3.0   \n",
       "109       1      225       2  878542738          3.0   \n",
       "116       1      233       2  878542552          3.0   \n",
       "124       1      252       2  875240677          3.0   \n",
       "127       1      255       2  885345822          3.0   \n",
       "132       1      264       2  875071713          3.0   \n",
       "11        1       36       2  875073180          2.0   \n",
       "65        1      143       1  875072631          4.0   \n",
       "105       1      219       1  878542327          4.0   \n",
       "30        1       74       1  889751736          3.0   \n",
       "51        1      112       1  878542441          3.0   \n",
       "64        1      140       1  878543133          3.0   \n",
       "129       1      259       1  875692979          3.0   \n",
       "130       1      260       1  875071713          3.0   \n",
       "134       1      266       1  885345728          3.0   \n",
       "32        1       78       1  878543176          2.0   \n",
       "47        1      103       1  878542845          2.0   \n",
       "48        1      104       1  875241619          2.0   \n",
       "56        1      120       1  875241637          2.0   \n",
       "121       1      243       1  875241390          2.0   \n",
       "126       1      254       1  878541392          2.0   \n",
       "\n",
       "                                            movie_name  \n",
       "2                           Usual Suspects, The (1995)  \n",
       "20                           Three Colors: Blue (1993)  \n",
       "23                    Shawshank Redemption, The (1994)  \n",
       "45                                        Fargo (1996)  \n",
       "53   Wallace & Gromit: The Best of Aardman Animatio...  \n",
       "78                              Cinema Paradiso (1988)  \n",
       "79                                 Delicatessen (1991)  \n",
       "80                      Raiders of the Lost Ark (1981)  \n",
       "84                                        Alien (1979)  \n",
       "90                                      Henry V (1989)  \n",
       "0    Shanghai Triad (Yao a yao yao dao waipo qiao) ...  \n",
       "3                                   Postino, Il (1994)  \n",
       "34                         Hudsucker Proxy, The (1994)  \n",
       "38                      Remains of the Day, The (1993)  \n",
       "40              Nightmare Before Christmas, The (1993)  \n",
       "42                   Terminator 2: Judgment Day (1991)  \n",
       "52   Horseman on the Roof, The (Hussard sur le toit...  \n",
       "60                                        Bound (1996)  \n",
       "68                                     Swingers (1996)  \n",
       "70                 Monty Python's Life of Brian (1979)  \n",
       "81                                       Brazil (1985)  \n",
       "82              Good, The Bad and The Ugly, The (1966)  \n",
       "92                           Dead Poets Society (1989)  \n",
       "95                                Groundhog Day (1993)  \n",
       "97                           Young Frankenstein (1974)  \n",
       "106                          Breaking the Waves (1996)  \n",
       "108                                    Ridicule (1996)  \n",
       "112                Star Trek: The Wrath of Khan (1982)  \n",
       "120                                       Kolya (1996)  \n",
       "125                            Pillow Book, The (1995)  \n",
       "..                                                 ...  \n",
       "58                                   Phenomenon (1996)  \n",
       "61                                  Kansas City (1996)  \n",
       "73                               Basic Instinct (1992)  \n",
       "115                                  Young Guns (1988)  \n",
       "101                         Room with a View, A (1986)  \n",
       "8                                      Bad Boys (1995)  \n",
       "46                              Aristocats, The (1970)  \n",
       "66                           Lawnmower Man, The (1992)  \n",
       "67                  Ghost and the Darkness, The (1996)  \n",
       "71                                Dirty Dancing (1987)  \n",
       "109                              101 Dalmatians (1996)  \n",
       "116                                 Under Siege (1992)  \n",
       "124              Lost World: Jurassic Park, The (1997)  \n",
       "127                    My Best Friend's Wedding (1997)  \n",
       "132                                       Mimic (1997)  \n",
       "11                                     Mad Love (1995)  \n",
       "65                          Sound of Music, The (1965)  \n",
       "105                  Nightmare on Elm Street, A (1984)  \n",
       "30                 Faster Pussycat! Kill! Kill! (1965)  \n",
       "51                                      Flipper (1996)  \n",
       "64       Homeward Bound: The Incredible Journey (1993)  \n",
       "129                        George of the Jungle (1997)  \n",
       "130                               Event Horizon (1997)  \n",
       "134                          Kull the Conqueror (1997)  \n",
       "32                                   Free Willy (1993)  \n",
       "47                      All Dogs Go to Heaven 2 (1996)  \n",
       "48                                 Theodore Rex (1995)  \n",
       "56                                   Striptease (1996)  \n",
       "121                               Jungle2Jungle (1997)  \n",
       "126                              Batman & Robin (1997)  \n",
       "\n",
       "[137 rows x 6 columns]"
      ]
     },
     "execution_count": 177,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Check evaluation results for the UserID = 1 \n",
    "test_ratings_df[test_ratings_df['userID'] == 1].sort_values(['rating','predictions'],ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Check UserID = 1 movie ratings in train dataset**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>userID</th>\n",
       "      <th>movieID</th>\n",
       "      <th>rating</th>\n",
       "      <th>timestamp</th>\n",
       "      <th>movie_name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>874965758</td>\n",
       "      <td>Toy Story (1995)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>1</td>\n",
       "      <td>119</td>\n",
       "      <td>5</td>\n",
       "      <td>876893098</td>\n",
       "      <td>Maya Lin: A Strong Clear Vision (1994)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89</th>\n",
       "      <td>1</td>\n",
       "      <td>168</td>\n",
       "      <td>5</td>\n",
       "      <td>874965478</td>\n",
       "      <td>Monty Python and the Holy Grail (1974)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>1</td>\n",
       "      <td>166</td>\n",
       "      <td>5</td>\n",
       "      <td>874965677</td>\n",
       "      <td>Manon of the Spring (Manon des sources) (1986)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>1</td>\n",
       "      <td>165</td>\n",
       "      <td>5</td>\n",
       "      <td>874965518</td>\n",
       "      <td>Jean de Florette (1986)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>1</td>\n",
       "      <td>152</td>\n",
       "      <td>5</td>\n",
       "      <td>878542589</td>\n",
       "      <td>Sleeper (1973)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>1</td>\n",
       "      <td>137</td>\n",
       "      <td>5</td>\n",
       "      <td>875071541</td>\n",
       "      <td>Big Night (1996)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>1</td>\n",
       "      <td>124</td>\n",
       "      <td>5</td>\n",
       "      <td>875071484</td>\n",
       "      <td>Lone Star (1996)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>1</td>\n",
       "      <td>115</td>\n",
       "      <td>5</td>\n",
       "      <td>878541637</td>\n",
       "      <td>Haunted World of Edward D. Wood Jr., The (1995)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>1</td>\n",
       "      <td>172</td>\n",
       "      <td>5</td>\n",
       "      <td>874965478</td>\n",
       "      <td>Empire Strikes Back, The (1980)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>59</th>\n",
       "      <td>1</td>\n",
       "      <td>111</td>\n",
       "      <td>5</td>\n",
       "      <td>889751711</td>\n",
       "      <td>Truth About Cats &amp; Dogs, The (1996)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>57</th>\n",
       "      <td>1</td>\n",
       "      <td>109</td>\n",
       "      <td>5</td>\n",
       "      <td>874965739</td>\n",
       "      <td>Mystery Science Theater 3000: The Movie (1996)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>1</td>\n",
       "      <td>93</td>\n",
       "      <td>5</td>\n",
       "      <td>875071484</td>\n",
       "      <td>Welcome to the Dollhouse (1995)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>1</td>\n",
       "      <td>89</td>\n",
       "      <td>5</td>\n",
       "      <td>875072484</td>\n",
       "      <td>Blade Runner (1982)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>1</td>\n",
       "      <td>87</td>\n",
       "      <td>5</td>\n",
       "      <td>878543541</td>\n",
       "      <td>Searching for Bobby Fischer (1993)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>1</td>\n",
       "      <td>59</td>\n",
       "      <td>5</td>\n",
       "      <td>876892817</td>\n",
       "      <td>Three Colors: Red (1994)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>90</th>\n",
       "      <td>1</td>\n",
       "      <td>169</td>\n",
       "      <td>5</td>\n",
       "      <td>878543541</td>\n",
       "      <td>Wrong Trousers, The (1993)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <td>1</td>\n",
       "      <td>173</td>\n",
       "      <td>5</td>\n",
       "      <td>878541803</td>\n",
       "      <td>Princess Bride, The (1987)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>1</td>\n",
       "      <td>55</td>\n",
       "      <td>5</td>\n",
       "      <td>875072688</td>\n",
       "      <td>Professional, The (1994)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>109</th>\n",
       "      <td>1</td>\n",
       "      <td>207</td>\n",
       "      <td>5</td>\n",
       "      <td>875073067</td>\n",
       "      <td>Cyrano de Bergerac (1990)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>133</th>\n",
       "      <td>1</td>\n",
       "      <td>270</td>\n",
       "      <td>5</td>\n",
       "      <td>888732827</td>\n",
       "      <td>Gattaca (1997)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>132</th>\n",
       "      <td>1</td>\n",
       "      <td>269</td>\n",
       "      <td>5</td>\n",
       "      <td>877482427</td>\n",
       "      <td>Full Monty, The (1997)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>131</th>\n",
       "      <td>1</td>\n",
       "      <td>268</td>\n",
       "      <td>5</td>\n",
       "      <td>875692927</td>\n",
       "      <td>Chasing Amy (1997)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>123</th>\n",
       "      <td>1</td>\n",
       "      <td>246</td>\n",
       "      <td>5</td>\n",
       "      <td>874965905</td>\n",
       "      <td>Chasing Amy (1997)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>114</th>\n",
       "      <td>1</td>\n",
       "      <td>223</td>\n",
       "      <td>5</td>\n",
       "      <td>876892918</td>\n",
       "      <td>Sling Blade (1996)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111</th>\n",
       "      <td>1</td>\n",
       "      <td>216</td>\n",
       "      <td>5</td>\n",
       "      <td>876892701</td>\n",
       "      <td>When Harry Met Sally... (1989)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>107</th>\n",
       "      <td>1</td>\n",
       "      <td>204</td>\n",
       "      <td>5</td>\n",
       "      <td>875072688</td>\n",
       "      <td>Back to the Future (1985)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>1</td>\n",
       "      <td>176</td>\n",
       "      <td>5</td>\n",
       "      <td>876892468</td>\n",
       "      <td>Aliens (1986)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>104</th>\n",
       "      <td>1</td>\n",
       "      <td>198</td>\n",
       "      <td>5</td>\n",
       "      <td>878542717</td>\n",
       "      <td>Nikita (La Femme Nikita) (1990)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>103</th>\n",
       "      <td>1</td>\n",
       "      <td>197</td>\n",
       "      <td>5</td>\n",
       "      <td>875072956</td>\n",
       "      <td>Graduate, The (1967)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>1</td>\n",
       "      <td>30</td>\n",
       "      <td>3</td>\n",
       "      <td>878542515</td>\n",
       "      <td>Belle de jour (1967)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>112</th>\n",
       "      <td>1</td>\n",
       "      <td>217</td>\n",
       "      <td>3</td>\n",
       "      <td>876892676</td>\n",
       "      <td>Bram Stoker's Dracula (1992)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>1</td>\n",
       "      <td>38</td>\n",
       "      <td>3</td>\n",
       "      <td>878543075</td>\n",
       "      <td>Net, The (1995)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>121</th>\n",
       "      <td>1</td>\n",
       "      <td>244</td>\n",
       "      <td>2</td>\n",
       "      <td>887431973</td>\n",
       "      <td>Smilla's Sense of Snow (1997)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>117</th>\n",
       "      <td>1</td>\n",
       "      <td>237</td>\n",
       "      <td>2</td>\n",
       "      <td>875071749</td>\n",
       "      <td>Jerry Maguire (1996)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>122</th>\n",
       "      <td>1</td>\n",
       "      <td>245</td>\n",
       "      <td>2</td>\n",
       "      <td>875071713</td>\n",
       "      <td>Devil's Own, The (1997)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>1</td>\n",
       "      <td>63</td>\n",
       "      <td>2</td>\n",
       "      <td>878543196</td>\n",
       "      <td>Santa Clause, The (1994)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>55</th>\n",
       "      <td>1</td>\n",
       "      <td>105</td>\n",
       "      <td>2</td>\n",
       "      <td>875240739</td>\n",
       "      <td>Sgt. Bilko (1996)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>1</td>\n",
       "      <td>11</td>\n",
       "      <td>2</td>\n",
       "      <td>875072262</td>\n",
       "      <td>Seven (Se7en) (1995)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>1</td>\n",
       "      <td>41</td>\n",
       "      <td>2</td>\n",
       "      <td>876892818</td>\n",
       "      <td>Billy Madison (1995)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>1</td>\n",
       "      <td>142</td>\n",
       "      <td>2</td>\n",
       "      <td>878543238</td>\n",
       "      <td>Bedknobs and Broomsticks (1971)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>1</td>\n",
       "      <td>149</td>\n",
       "      <td>2</td>\n",
       "      <td>878542791</td>\n",
       "      <td>Jude (1996)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>1</td>\n",
       "      <td>34</td>\n",
       "      <td>2</td>\n",
       "      <td>878542869</td>\n",
       "      <td>Doom Generation, The (1995)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>1</td>\n",
       "      <td>126</td>\n",
       "      <td>2</td>\n",
       "      <td>875071713</td>\n",
       "      <td>Spitfire Grill, The (1996)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>1</td>\n",
       "      <td>167</td>\n",
       "      <td>2</td>\n",
       "      <td>878542383</td>\n",
       "      <td>Private Benjamin (1980)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>134</th>\n",
       "      <td>1</td>\n",
       "      <td>271</td>\n",
       "      <td>2</td>\n",
       "      <td>887431672</td>\n",
       "      <td>Starship Troopers (1997)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>1</td>\n",
       "      <td>37</td>\n",
       "      <td>2</td>\n",
       "      <td>878543030</td>\n",
       "      <td>Nadja (1994)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>54</th>\n",
       "      <td>1</td>\n",
       "      <td>101</td>\n",
       "      <td>2</td>\n",
       "      <td>878542845</td>\n",
       "      <td>Heavy Metal (1981)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>1</td>\n",
       "      <td>94</td>\n",
       "      <td>2</td>\n",
       "      <td>875072956</td>\n",
       "      <td>Home Alone (1990)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>1</td>\n",
       "      <td>21</td>\n",
       "      <td>1</td>\n",
       "      <td>878542772</td>\n",
       "      <td>Muppet Treasure Island (1996)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>1</td>\n",
       "      <td>29</td>\n",
       "      <td>1</td>\n",
       "      <td>878542869</td>\n",
       "      <td>Batman Forever (1995)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58</th>\n",
       "      <td>1</td>\n",
       "      <td>110</td>\n",
       "      <td>1</td>\n",
       "      <td>878542845</td>\n",
       "      <td>Operation Dumbo Drop (1995)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1</td>\n",
       "      <td>8</td>\n",
       "      <td>1</td>\n",
       "      <td>875072484</td>\n",
       "      <td>Babe (1995)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>68</th>\n",
       "      <td>1</td>\n",
       "      <td>131</td>\n",
       "      <td>1</td>\n",
       "      <td>878542552</td>\n",
       "      <td>Breakfast at Tiffany's (1961)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>1</td>\n",
       "      <td>35</td>\n",
       "      <td>1</td>\n",
       "      <td>878542420</td>\n",
       "      <td>Free Willy 2: The Adventure Home (1995)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>129</th>\n",
       "      <td>1</td>\n",
       "      <td>261</td>\n",
       "      <td>1</td>\n",
       "      <td>875692992</td>\n",
       "      <td>Air Bud (1997)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>130</th>\n",
       "      <td>1</td>\n",
       "      <td>263</td>\n",
       "      <td>1</td>\n",
       "      <td>875693007</td>\n",
       "      <td>Steel (1997)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>115</th>\n",
       "      <td>1</td>\n",
       "      <td>231</td>\n",
       "      <td>1</td>\n",
       "      <td>876893031</td>\n",
       "      <td>Batman Returns (1992)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>1</td>\n",
       "      <td>138</td>\n",
       "      <td>1</td>\n",
       "      <td>878543006</td>\n",
       "      <td>D3: The Mighty Ducks (1996)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>124</th>\n",
       "      <td>1</td>\n",
       "      <td>247</td>\n",
       "      <td>1</td>\n",
       "      <td>875241619</td>\n",
       "      <td>Turbo: A Power Rangers Movie (1997)</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>135 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     userID  movieID  rating  timestamp  \\\n",
       "0         1        1       5  874965758   \n",
       "62        1      119       5  876893098   \n",
       "89        1      168       5  874965478   \n",
       "87        1      166       5  874965677   \n",
       "86        1      165       5  874965518   \n",
       "81        1      152       5  878542589   \n",
       "72        1      137       5  875071541   \n",
       "65        1      124       5  875071484   \n",
       "60        1      115       5  878541637   \n",
       "91        1      172       5  874965478   \n",
       "59        1      111       5  889751711   \n",
       "57        1      109       5  874965739   \n",
       "50        1       93       5  875071484   \n",
       "49        1       89       5  875072484   \n",
       "47        1       87       5  878543541   \n",
       "38        1       59       5  876892817   \n",
       "90        1      169       5  878543541   \n",
       "92        1      173       5  878541803   \n",
       "35        1       55       5  875072688   \n",
       "109       1      207       5  875073067   \n",
       "133       1      270       5  888732827   \n",
       "132       1      269       5  877482427   \n",
       "131       1      268       5  875692927   \n",
       "123       1      246       5  874965905   \n",
       "114       1      223       5  876892918   \n",
       "111       1      216       5  876892701   \n",
       "107       1      204       5  875072688   \n",
       "93        1      176       5  876892468   \n",
       "104       1      198       5  878542717   \n",
       "103       1      197       5  875072956   \n",
       "..      ...      ...     ...        ...   \n",
       "20        1       30       3  878542515   \n",
       "112       1      217       3  876892676   \n",
       "25        1       38       3  878543075   \n",
       "121       1      244       2  887431973   \n",
       "117       1      237       2  875071749   \n",
       "122       1      245       2  875071713   \n",
       "39        1       63       2  878543196   \n",
       "55        1      105       2  875240739   \n",
       "8         1       11       2  875072262   \n",
       "27        1       41       2  876892818   \n",
       "76        1      142       2  878543238   \n",
       "80        1      149       2  878542791   \n",
       "22        1       34       2  878542869   \n",
       "66        1      126       2  875071713   \n",
       "88        1      167       2  878542383   \n",
       "134       1      271       2  887431672   \n",
       "24        1       37       2  878543030   \n",
       "54        1      101       2  878542845   \n",
       "51        1       94       2  875072956   \n",
       "14        1       21       1  878542772   \n",
       "19        1       29       1  878542869   \n",
       "58        1      110       1  878542845   \n",
       "6         1        8       1  875072484   \n",
       "68        1      131       1  878542552   \n",
       "23        1       35       1  878542420   \n",
       "129       1      261       1  875692992   \n",
       "130       1      263       1  875693007   \n",
       "115       1      231       1  876893031   \n",
       "73        1      138       1  878543006   \n",
       "124       1      247       1  875241619   \n",
       "\n",
       "                                          movie_name  \n",
       "0                                   Toy Story (1995)  \n",
       "62            Maya Lin: A Strong Clear Vision (1994)  \n",
       "89            Monty Python and the Holy Grail (1974)  \n",
       "87    Manon of the Spring (Manon des sources) (1986)  \n",
       "86                           Jean de Florette (1986)  \n",
       "81                                    Sleeper (1973)  \n",
       "72                                  Big Night (1996)  \n",
       "65                                  Lone Star (1996)  \n",
       "60   Haunted World of Edward D. Wood Jr., The (1995)  \n",
       "91                   Empire Strikes Back, The (1980)  \n",
       "59               Truth About Cats & Dogs, The (1996)  \n",
       "57    Mystery Science Theater 3000: The Movie (1996)  \n",
       "50                   Welcome to the Dollhouse (1995)  \n",
       "49                               Blade Runner (1982)  \n",
       "47                Searching for Bobby Fischer (1993)  \n",
       "38                          Three Colors: Red (1994)  \n",
       "90                        Wrong Trousers, The (1993)  \n",
       "92                        Princess Bride, The (1987)  \n",
       "35                          Professional, The (1994)  \n",
       "109                        Cyrano de Bergerac (1990)  \n",
       "133                                   Gattaca (1997)  \n",
       "132                           Full Monty, The (1997)  \n",
       "131                               Chasing Amy (1997)  \n",
       "123                               Chasing Amy (1997)  \n",
       "114                               Sling Blade (1996)  \n",
       "111                   When Harry Met Sally... (1989)  \n",
       "107                        Back to the Future (1985)  \n",
       "93                                     Aliens (1986)  \n",
       "104                  Nikita (La Femme Nikita) (1990)  \n",
       "103                             Graduate, The (1967)  \n",
       "..                                               ...  \n",
       "20                              Belle de jour (1967)  \n",
       "112                     Bram Stoker's Dracula (1992)  \n",
       "25                                   Net, The (1995)  \n",
       "121                    Smilla's Sense of Snow (1997)  \n",
       "117                             Jerry Maguire (1996)  \n",
       "122                          Devil's Own, The (1997)  \n",
       "39                          Santa Clause, The (1994)  \n",
       "55                                 Sgt. Bilko (1996)  \n",
       "8                               Seven (Se7en) (1995)  \n",
       "27                              Billy Madison (1995)  \n",
       "76                   Bedknobs and Broomsticks (1971)  \n",
       "80                                       Jude (1996)  \n",
       "22                       Doom Generation, The (1995)  \n",
       "66                        Spitfire Grill, The (1996)  \n",
       "88                           Private Benjamin (1980)  \n",
       "134                         Starship Troopers (1997)  \n",
       "24                                      Nadja (1994)  \n",
       "54                                Heavy Metal (1981)  \n",
       "51                                 Home Alone (1990)  \n",
       "14                     Muppet Treasure Island (1996)  \n",
       "19                             Batman Forever (1995)  \n",
       "58                       Operation Dumbo Drop (1995)  \n",
       "6                                        Babe (1995)  \n",
       "68                     Breakfast at Tiffany's (1961)  \n",
       "23           Free Willy 2: The Adventure Home (1995)  \n",
       "129                                   Air Bud (1997)  \n",
       "130                                     Steel (1997)  \n",
       "115                            Batman Returns (1992)  \n",
       "73                       D3: The Mighty Ducks (1996)  \n",
       "124              Turbo: A Power Rangers Movie (1997)  \n",
       "\n",
       "[135 rows x 5 columns]"
      ]
     },
     "execution_count": 144,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Check UserID = 1 movie ratings in train dataset\n",
    "train_ratings_df['movie_name'] = train_ratings_df['movieID'].apply(lambda x:movie_dict[x])\n",
    "train_ratings_df[train_ratings_df['userID'] == 1].sort_values(['rating'],ascending=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
